﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KMS.Core
{
   

    public partial class ServiceBase<T>
    {
        protected virtual bool OnBeforeInsert(InsertEventArgs<T> arg)
        {
            return true;
        }

        protected virtual void OnAfterInsert(InsertEventArgs<T> arg)
        {

        }
        public int Insert(T model)
        {
            var result = 0;

            QueryExcute(
                db =>
                {
                    var rtnBefore = this.OnBeforeInsert(new InsertEventArgs<T>() { Db = db, Data = model });
                    if (!rtnBefore) return;
                    result = db.InsertEntity(model);
                    this.OnAfterInsert(new InsertEventArgs<T>() { Db = db, Data = model, ExecuteValue = result });
                }
                );
           
            return result;
        }
 
    }
}
